package com.jk.vehicle.mini.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.jk.vehicle.mini.entity.MileageStatisticsWeek;
import com.jk.vehicle.mini.service.MileageStatisticsWeekService;
import com.jk.vehicle.mini.dao.MileageStatisticsWeekMapper;
import com.jk.vehicle.core.service.impl.AbstractService;
import com.jk.vehicle.mini.util.QueryUtil;
import com.jk.vehicle.mini.util.SequenceUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.EntityColumn;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.mapperhelper.EntityHelper;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Date;

/**
 * This is Description for MileageStatisticsWeekServiceImpl
 *
 * @author zhangdongdong
 * @date 2021/02/09
 */
@Service
public class MileageStatisticsWeekServiceImpl extends AbstractService<MileageStatisticsWeek> implements MileageStatisticsWeekService {
    /**
	 * 注入MileageStatisticsWeekMapper
	 */
    @Resource
    private MileageStatisticsWeekMapper mileageStatisticsWeekMapper;

    /**
    * 根据查询条件查询单表数据
    * @param paramMap 查询条件
    * @return 查询结果
    */
    @Override
    @DS("#last")
    public List<MileageStatisticsWeek> queryByParams(Map<String, Object> paramMap, String dsName){
        Condition condition = new Condition(MileageStatisticsWeek.class);
        Example.Criteria criteria = condition.createCriteria();
        Map<String, EntityColumn> propertyMap = EntityHelper.getEntityTable(MileageStatisticsWeek.class).getPropertyMap();
        QueryUtil.spliceQueryParam(criteria, paramMap,  propertyMap, condition);
        return mileageStatisticsWeekMapper.selectByCondition(condition);
    }

    @Override
    @DS("#last")
    public void save(MileageStatisticsWeek mileageStatisticsWeek, String dsName) {
        mileageStatisticsWeek.setId(SequenceUtils.nextId());
        mileageStatisticsWeek.setCreateDate(new Date());
        super.save(mileageStatisticsWeek, dsName);
    }

    @Override
    @DS("#last")
    public void update(MileageStatisticsWeek mileageStatisticsWeek, String dsName){
        mileageStatisticsWeek.setUpdateDate(new Date());
        super.update(mileageStatisticsWeek, dsName);
    }
}
